package databaseVersionControl.domain.control;

public abstract class AbstractScriptKey {

	protected String databaseScriptKey;
	protected int number;
	private boolean isSystem;

	protected AbstractScriptKey() {
	}

	public AbstractScriptKey(String databaseScriptKey, int number) {
		setDatabaseScriptKey(databaseScriptKey);
		setNumber(number);
		setSystem(false);
	}

	protected void setDatabaseScriptKey(String databaseScriptKey) {
		this.databaseScriptKey = databaseScriptKey;
	}

	protected void setNumber(int number) {
		this.number = number;
	}

	public String getDatabaseScriptKey() {
		return databaseScriptKey;
	}

	public int getNumber() {
		return number;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;

		if (!(obj instanceof AbstractScriptKey))
			return false;

		AbstractScriptKey anotherKey = (AbstractScriptKey) obj;

		return getDatabaseScriptKey().equals(anotherKey.getDatabaseScriptKey())
				&& getNumber() == anotherKey.getNumber();
	}
	
	@Override
	public int hashCode() {
		return toString().hashCode();
	}
	
	@Override
	public String toString() {
		return getDatabaseScriptKey() + " - " + getNumber();
	}

	public void setSystem(boolean isSystem) {
		this.isSystem = isSystem;
	}

	public boolean isSystemKey() {
		return isSystem;
	}
}